package yunjiao.designpatterns.combinator;

/**
 * 解析结果
 *
 * @author yangyunjiao
 */
public class ParseResult<T> {
    public final T value;
    public final String remaining;
    public final boolean success;
    public final String error;

    private ParseResult(T value, String remaining, boolean success, String error) {
        this.value = value;
        this.remaining = remaining;
        this.success = success;
        this.error = error;
    }

    public static <T> ParseResult<T> success(T value, String remaining) {
        return new ParseResult<>(value, remaining, true, null);
    }

    public static <T> ParseResult<T> failure(String error) {
        return new ParseResult<>(null, null, false, error);
    }
}
